package com.tuanzi.loan.web.bean.templateConf;

import com.tuanzi.loan.business.service.templateConf.ActivityItemService;
import com.tuanzi.loan.business.service.templateConf.ActivityService;
import com.tuanzi.loan.core.aspect.Debug;
import com.tuanzi.loan.vo.request.templateConf.ActivityRequest;
import com.tuanzi.loan.vo.response.templateConf.ActivityResponse;
import com.tuanzi.loan.web.configuration.JSFListingSessionBean;
import com.tuanzi.loan.web.lazy.templateConf.ActivityLazyDataModel;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import javax.faces.bean.ViewScoped;

/**
 * 甲方资料填写模板配置
 */
@Debug
@Component
@ViewScoped
public class ActivityListBean extends JSFListingSessionBean<ActivityRequest, ActivityResponse> {

    private static final long serialVersionUID = -7456998959122405455L;

    @Autowired
    private ActivityService activityService;
    @Autowired
    private ActivityItemService activityItemService;

    @Override
    protected String page() {
        return "/views/templateConf/activityConf/activitylist.xhtml";
    }

    @Override
    protected void initLazyDataModel() {
        $ = new ActivityRequest();
        lazyDataModel = new ActivityLazyDataModel($, session, activityService);
    }

    public void onReset() {
        initLazyDataModel();
    }

    public String onAdd() {
        return redirect("/views/templateConf/activityConf/activityItemList.xhtml");
    }

    public String onEdit(Long id) {
        return redirect("/views/templateConf/activityConf/activityItemList?id=" + id);
    }

    public void onDelete(Long id) {
        activityService.delete(id);
        activityItemService.deleteByApiId(id);
    }

    public void changeStatus(Long id, Short status) {
        activityService.offLine(id, status);
    }

    public String onCopy(Long id) {
        return redirect("/views/templateConf/activityConf/activityItemList?id=" + id + "&copy=1");
    }

}
